package com.witdata.controller.community;

import com.witdata.common.domain.Result;
import com.witdata.common.domain.Status;
import com.witdata.common.domain.dto.ArticleLikeDto;
import com.witdata.common.service.community.ArticleLikeService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LiuQi
 */
@RestController
@RequestMapping("/community/article/like")
@RequiredArgsConstructor
public class ArticleLikeController {
    private final ArticleLikeService articleLikeService;

    /**
     * 获取用户点赞列表
     */
    @GetMapping("/list")
    public Result <List<ArticleLikeDto>> getArticleLikeList() {
        List<ArticleLikeDto> articleLikeList = articleLikeService.getArticleLikeList();
        return Result.ok(Status.SUCCESS, articleLikeList);
    }

    /**
     * 点赞
     */
    @PostMapping("/publish")
    public Result <String> likeArticle(@RequestParam("articleId") Long articleId) {
        articleLikeService.likeArticle(articleId);
        return Result.ok(Status.LIKESUCCESS);
    }

    /**
     * 取消点赞
     */
    @PostMapping("/cancel")
    public Result <String> unlikeArticle(@RequestParam("articleId") Long articleId) {
        articleLikeService.unlikeArticle(articleId);
        return Result.ok(Status.CANCELSUCCESS);
    }
}
